<template>
<view>
<swiper-direct-com
  :lrDistance="5"
  ref="direct"
  leftMed="scrollL"
  rightMed="scrollR"
  @scrollL="scrollL"
  @scrollR="scrollR">
<view style="padding-bottom: 1px;min-height: 100vh;">
	<v-tabs v-if="roles == 'head'" v-model="tabVal" :scroll="false" :tabs="['未整改', '未审核']" :fixed="true" @change="changeTab"></v-tabs>
	<view v-show="tabVal == 0 || roles != 'head'">
		<view v-for="(item, index) in list">
			<uni-card :title="item.warnType" :sub-title="getdatatime(item.warnTime)" :is-shadow="false" @click="cardClick(item, index)"></uni-card>
		</view>
		<uni-card v-if="list.length == 0" :is-shadow="false">
			<image src="../static/images/empty-image-default.png" style="width: 176px;height: 176px;margin-left: calc(50% - 88px);"></image>
			<view  style="width: 100%;text-align: center;color: #969799;font-size: 15px;">暂无数据</view>
		</uni-card>
	</view>
	<view v-show="tabVal == 1">
		<view v-for="(item, index) in examineList">
			<uni-card :title="item.warnType" :sub-title="getdatatime(item.warnTime)" :is-shadow="false" @click="cardClick(item, index)"></uni-card>
		</view>
		<uni-card v-if="examineList.length == 0" :is-shadow="false">
			<image src="../static/images/empty-image-default.png" style="width: 176px;height: 176px;margin-left: calc(50% - 88px);"></image>
			<view  style="width: 100%;text-align: center;color: #969799;font-size: 15px;">暂无数据</view>
		</uni-card>
	</view>
</view>
</swiper-direct-com>
</view>
</template>

<script>
import swiperDirectCom from '@/components/swiper-direct-com.vue'
import vTabs from '@/components/v-tabs.vue'
import {getEventDictList, getAuditEventList, getDetectionObjectDictList, getDataUnitDictList, getAllEventListByHead, getEventListByRectifier} from "@/api/system/uniapp.js"

export default {
	components:{
		swiperDirectCom,
		vTabs
	},
	data() {
	    return {
	      tabVal: 0,
		  list: [],
		  examineList: [],
		  eventDictList: [],
		  detectionObjectDictList: [],
		  dataUnitDictList: [],
		  page:{
			  pageNum: 1,
			  pageSize: 10,
			  total: 0
		  },
		  roles: uni.getStorageSync('storage_data').vuex_roles.join(),
	    }
	},
    onLoad: function() {
		// this.getEventDictList();
		this.getDetectionObjectDictList();
		this.getDataUnitDictList();
		if(this.roles == "head"){
			this.getAllEventListByHead();
		}else{
			this.getEventListByRectifier();
		}
    },
	onShow(){
		const _this = this
		uni.$on('allocation',function(data){
			_this.list.splice(data.index,1);
		})
		uni.$on('examine',function(data){
			_this.examineList.splice(data.index,1);
		})
	},
	methods:{
		getAuditEventList(){
			getAuditEventList(this.page).then(res => {
				console.log("rrrr", res)
				this.examineList = res.data
			})
		},
		getAllEventListByHead(){
			getAllEventListByHead(this.page).then(res => {
				this.list = res.rows
				this.page.total = res.total
			})
		},
		getEventListByRectifier(){
			getEventListByRectifier(this.page).then(res => {
				this.list = res.rows
				this.page.total = res.total
			})
		},
		getEventDictList(){
			getEventDictList().then(res => {
				this.eventDictList = res.data
			})
		},
		getDetectionObjectDictList(){
			getDetectionObjectDictList().then(res => {
				this.detectionObjectDictList = res.data
			})
		},
		getDataUnitDictList(){
			getDataUnitDictList().then(res => {
				this.dataUnitDictList = res.data
			})
		},
		geteventCode(item){
			for(let i = 0;i < this.eventDictList.length;i++){
				if(this.eventDictList[i].code == item){
					return this.eventDictList[i].name
				}
			}
		},
		cardClick(item, index){
			if(this.roles == "head"){
				if(this.tabVal == 0){
					uni.navigateTo({
						url: '/pages/inspection/allocation?row=' + JSON.stringify({...item, index: index}),
					})
				}else{
					uni.navigateTo({
						url: '/pages/inspection/examine?row=' + JSON.stringify({...item, index: index}),
					})
				}
			}else{
				uni.navigateTo({
					url: '/pages/inspection/rectification?row=' + JSON.stringify({...item, index: index}),
				})
			}
		},
		changeTab(index) {
			this.tabVal = index
		},
		scrollL() {
			if(this.roles == "head"){
				if(this.tabVal == 1) return
				this.tabVal += 1;
				this.getAuditEventList()
				this.$refs.direct.toTop()
			}
		},
		scrollR() {
			if(this.roles == "head"){
				if(this.tabVal == 0) return
				this.tabVal -= 1;
				this.$refs.direct.toTop()
			}
		},
		getdatatime(time, type) {
		  if (!time) {
			return "暂无数据";
		  }
		  const dt = new Date(parseInt(time));
		  const y = dt.getFullYear();
		  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
		  const d = (dt.getDate() + "").padStart(2, "0");
		  const hh = (dt.getHours() + "").padStart(2, "0");
		  const mm = (dt.getMinutes() + "").padStart(2, "0");
		  const ss = (dt.getSeconds() + "").padStart(2, "0");
		  return `${y}年${m}月${d}日 ${hh}:${mm}:${ss}`;
		},
	}
  }
</script>

<style lang="scss">
page{
    background-color: #f5f6f7;
}
.content{
	font-size: 16px;
	font-weight: 500;
	min-height: 45px;
	display: flow-root;
}
.card_bottom_view{
	height: 20px;
	line-height: 20px;
	margin-right: 10px;
	font-size: 14px;
	float: left;
}
.card_bottom_span{
	font-weight: bold;
	font-size: 14px;
}
.reject_button{
	background-color: #ecf5ff;
	color: #409eff;
	border: 1px solid #b3d8ff;
	width: 150px;
	font-size: 14px;
	float: right;
}
.white_button{
	background-color: #ffffff;
	color: #000000;
	border: 1px solid #dcdfe6;
	width: 150px;
	font-size: 14px;
	float: left;
}
#sign_button{
	background-color: #f0f9eb;
	color: #67c23a;
	border: 1px solid #c2e7b0;
	width: 100px;
	font-size: 14px;
	margin-left: calc(50% - 110px);
	float: left;
}
</style>
